package com.future.servlet;

import com.future.biz.AreaBIZ;
import com.future.model.bo.AreaBO;
import net.sf.json.JSONObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class PickAreaServlet extends HttpServlet {

	private static Logger logger = LogManager.getLogger(PickAreaServlet.class);

	public PickAreaServlet() {
		super();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/plain;charset=utf-8");
		PrintWriter out = response.getWriter();
		logger.debug("this is doget");
		AreaBIZ areaBiz = new AreaBIZ();
		String flag = request.getParameter("flag");
		String code = request.getParameter("code");
		logger.debug(code);
		AreaBO areaBo = null;
		if(flag!=null&&!("").equals(flag)&&("aa").equals(flag)){
			areaBo = areaBiz.generateLowerAreaBO(code,flag);
		}else {
			areaBo = areaBiz.generateLowerAreaBO(code);
		}
		logger.debug(areaBo);
		JSONObject json = JSONObject.fromObject(areaBo);
		out.print(json);
		out.flush();
		out.close();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		logger.debug("this is doPost");
	}

}
